<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractCode']" disabled placeholder="请输入合同编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="甲方编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['item', validatorRules.item]"
                :trigger-change="true"
                org-fields="item,company,deposit_park,park_number"
                dest-fields="item,company,depositPark,parkNumber"
                code="v_xy_park_accountinfo"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="甲方（物业公司）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['company']" disabled placeholder="请输入甲方（物业公司）"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['depositPark']" disabled placeholder="请输入开户银行"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="开户账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['parkNumber']" disabled placeholder="请输入开户账号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="业主编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['ownerCode', validatorRules.ownerCode]"
                :trigger-change="true"
                org-fields="owner_code,owner_name,social_creditcode,id_card,contact_tel"
                dest-fields="ownerCode,ownerName,socialCreditcode,idNumber,contactMethod"
                code="v_xy_park_owner"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="业主名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ownerName']" disabled placeholder="请输入业主名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['socialCreditcode']" disabled placeholder="请输入社会信用代码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['idNumber']" disabled placeholder="请输入身份证号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contactMethod']" placeholder="请输入联系电话"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['projectCode']"
                :trigger-change="true"
                org-fields="project_code,project_name"
                dest-fields="projectCode,projectName"
                code="v_xy_park_projectinfo"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectName']" disabled placeholder="请输入项目名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="服务面积" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number disabled v-decorator="['serviceArea', validatorRules.serviceArea]" placeholder="请输入服务面积" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="综合服务费总额（小写）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['totalAmount', validatorRules.totalAmount]" @change="handleChangeTotal" placeholder="请输入综合服务费总额（小写）" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="综合服务费总额（大写）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['amountDetail']" disabled placeholder="请输入综合服务费总额（大写）"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="综合服务费标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['amountStandard', validatorRules.amountStandard]" placeholder="请输入综合服务费标准" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="服务开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择服务开始时间" v-decorator="['serviceStarttime', validatorRules.serviceStarttime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="服务结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择服务结束时间" v-decorator="['serviceEndtime', validatorRules.serviceEndtime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="缴费方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['paymentMethod', validatorRules.paymentMethod]" :trigger-change="true" dictCode="xy_park_contract_cycle" placeholder="请选择缴费方式"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="装修保证金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['earnestMoney', validatorRules.earnestMoney]" placeholder="请输入装修保证金" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="是否三七" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isThreeSeven', validatorRules.isThreeSeven]" ></j-switch>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="合同附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['contractFile']" :trigger-change="true"></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="物业合同房源信息" :key="refKeys[0]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[0]"
          :loading="xyParkPropertycontractDetailTable.loading"
          :columns="xyParkPropertycontractDetailTable.columns"
          :dataSource="xyParkPropertycontractDetailTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"
          @deleted="setServiceArea"
        >
          <template #houseCode="props">
            <j-popup
              :trigger-change="true"
              :value="props.value"
              :multi="true"
              org-fields="house_code,building,building_name,project,project_name,floor,building_area,property_area,decoration,house_type"
              dest-fields="houseCode,buildingCode,buildingName,projectCode,projectName,floor,buildingArea,propertyArea,decoration,houseType"
              code="v_xy_park_houseing"
              @callback="(row) => houseCodeCallback(row,props)"/>
          </template>
        </j-editable-table>
      </a-tab-pane>
      <a-tab-pane tab="物业合同款项信息" :key="refKeys[1]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[1]"
          :loading="xyParkPropertycontractPayinfoTable.loading"
          :columns="xyParkPropertycontractPayinfoTable.columns"
          :dataSource="xyParkPropertycontractPayinfoTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
      <a-tab-pane tab="免物业费期" :key="refKeys[2]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[2]"
          :loading="xyParkPropertycontractFreeperiodTable.loading"
          :columns="xyParkPropertycontractFreeperiodTable.columns"
          :dataSource="xyParkPropertycontractFreeperiodTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>

import pick from 'lodash.pick'
// import { getAction } from '@/api/manage'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
// import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import JDate from '@/components/jeecg/JDate'
import JUpload from '@/components/jeecg/JUpload'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSwitch from '@/components/jeecg/JSwitch'

export default {
  name: 'XyParkPropertycontractForm',
  mixins: [JEditableTableMixin],
  components: {
    JFormContainer,
    JDate,
    JUpload,
    JDictSelectTag,
    JSwitch
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {
        item: {
          rules: [
            { required: true, message: '请选择甲方!' }
          ]
        },
        ownerCode: {
          rules: [
            { required: true, message: '请选择业主!' }
          ]
        },
        serviceArea: {
          rules: [
            { required: true, message: '请输入服务面积!' }
          ]
        },
        totalAmount: {
          rules: [
            { required: true, message: '请输入综合服务费总额（小写）!' }
          ]
        },
        amountStandard: {
          rules: [
            { required: true, message: '请输入综合服务费标准!' }
          ]
        },
        serviceStarttime: {
          rules: [
            { required: true, message: '请输入服务开始时间!' },
            { validator: this.validateServicetime }
          ]
        },
        serviceEndtime: {
          rules: [
            { required: true, message: '请输入服务结束时间!' },
            { validator: this.validateServicetime }
          ]
        },
        paymentMethod: {
          rules: [
            { required: true, message: '请输入缴费方式!' }
          ]
        },
        earnestMoney: {
          rules: [
            { required: true, message: '请输入装修保证金!' }
          ]
        },
        isThreeSeven: {
          rules: [
            { required: true, message: '请输入是否三七!' }
          ]
        }
      },
      refKeys: ['xyParkPropertycontractDetail', 'xyParkPropertycontractPayinfo', 'xyParkPropertycontractFreeperiod'],
      tableKeys: ['xyParkPropertycontractDetail', 'xyParkPropertycontractPayinfo', 'xyParkPropertycontractFreeperiod'],
      activeKey: 'xyParkPropertycontractDetail',
      // 物业合同房源信息
      xyParkPropertycontractDetailTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '房源编号',
            key: 'houseCode',
            type: FormTypes.slot,
            slotName: 'houseCode',
            // type: FormTypes.popup,
            // popupCode: 'v_xy_park_houseing',
            // destFields: 'houseCode,buildingCode,buildingName,projectCode,projectName,floor,buildingArea,propertyArea,decoration,houseType',
            // orgFields: 'house_code,building,building_name,project,project_name,floor,building_area,property_area,decoration,house_type',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { pattern: 'only', message: '${title}不能重复' }
            ]
          },
          {
            title: '楼宇名称',
            key: 'buildingName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '项目名称',
            key: 'projectName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '楼层',
            key: 'floor',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '建筑面积（㎡）',
            key: 'buildingArea',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '产权面积（㎡）',
            key: 'propertyArea',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '装修情况',
            key: 'decoration',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '房源类型',
            key: 'houseType',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },

          {
            title: 'house_code',
            key: 'house_code',
            type: 'hidden'
          },

          {
            title: 'building_code',
            key: 'building_code',
            type: 'hidden'
          },

          {
            title: 'building_name',
            key: 'building_name',
            type: 'hidden'
          },

          {
            title: 'project_code',
            key: 'project_code',
            type: 'hidden'
          },

          {
            title: 'project_name',
            key: 'project_name',
            type: 'hidden'
          },

          {
            title: 'building_area',
            key: 'building_area',
            type: 'hidden'
          },

          {
            title: 'property_area',
            key: 'property_area',
            type: 'hidden'
          },

          {
            title: 'house_type',
            key: 'house_type',
            type: 'hidden'
          }
        ]
      },
      // 物业合同款项信息
      xyParkPropertycontractPayinfoTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '费项',
            key: 'costType',
            type: FormTypes.popup,
            popupCode: 'v_xy_park_cost_type',
            destFields: 'costType,costName',
            orgFields: 'cost_type,cost_name',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '费项名称',
            key: 'costName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            disabled: true
          },
          {
            title: '金额',
            key: 'price',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '账单开始日期',
            key: 'startDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateDate }
            ]
          },
          {
            title: '账单结束日期',
            key: 'endDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateDate }
            ]
          },
          {
            title: '应收日期',
            key: 'collectionDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateCollectionDate }
            ]
          },

          {
            title: 'cost_type',
            key: 'cost_type',
            type: 'hidden'
          },

          {
            title: 'cost_name',
            key: 'cost_name',
            type: 'hidden'
          }
        ]
      },
      // 免租期
      xyParkPropertycontractFreeperiodTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '开始日期',
            key: 'startDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { handler: this.validateDate }
            ]
          },
          {
            title: '结束日期',
            key: 'endDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { handler: this.validateDate }
            ]
          }
        ]
      },
      url: {
        add: '/community/xyParkPropertycontract/add',
        edit: '/community/xyParkPropertycontract/edit',
        queryById: '/community/xyParkPropertycontract/queryById',
        xyParkPropertycontractDetail: {
          list: '/community/xyParkPropertycontract/queryXyParkPropertycontractDetailByMainId'
        },
        xyParkPropertycontractPayinfo: {
          list: '/community/xyParkPropertycontract/queryXyParkPropertycontractPayinfoByMainId'
        },
        xyParkPropertycontractFreeperiod: {
          list: '/community/xyParkPropertycontract/queryXyParkPropertycontractFreeperiodByMainId'
        }
      }
    }
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false
    },
    // 表单模式：false流程表单 true普通表单
    // formBpm: {
    //   type: Boolean,
    //   default: false,
    //   required: false
    // },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    }
    // showFlowSubmitButton() {
    //   if (this.formBpm === true) {
    //     if (this.formData.disabled === false) {
    //       return true
    //     }
    //   }
    //   return false
    // }
  },
  created() {
    // 如果是流程中表单，则需要加载流程表单data
    // this.showFlowData()
  },
  methods: {
    addBefore() {
      this.form.resetFields()
      this.xyParkPropertycontractDetailTable.dataSource = []
      this.xyParkPropertycontractPayinfoTable.dataSource = []
      this.xyParkPropertycontractFreeperiodTable.dataSource = []
    },
    getAllTable() {
      const values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      const fieldval = pick(this.model, 'createBy', 'createTime', 'contractCode', 'item', 'company', 'depositPark', 'parkNumber', 'ownerCode', 'ownerName', 'socialCreditcode', 'idNumber', 'contactMethod', 'projectCode', 'projectName', 'serviceArea', 'totalAmount', 'amountDetail', 'amountStandard', 'serviceStarttime', 'serviceEndtime', 'paymentMethod', 'earnestMoney', 'bpmStatus', 'isThreeSeven', 'contractFile')
      this.$nextTick(() => {
        this.form.setFieldsValue(fieldval)
      })
      // 加载子表数据
      if (this.model.contractCode) {
        const params = { id: this.model.contractCode }
        this.requestSubTableData(this.url.xyParkPropertycontractDetail.list, params, this.xyParkPropertycontractDetailTable)
        this.requestSubTableData(this.url.xyParkPropertycontractPayinfo.list, params, this.xyParkPropertycontractPayinfoTable)
        this.requestSubTableData(this.url.xyParkPropertycontractFreeperiod.list, params, this.xyParkPropertycontractFreeperiodTable)
      }
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      const main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        xyParkPropertycontractDetailList: allValues.tablesValue[0].values,
        xyParkPropertycontractPayinfoList: allValues.tablesValue[1].values,
        xyParkPropertycontractFreeperiodList: allValues.tablesValue[2].values
      }
    },
    // 渲染流程表单数据
    // showFlowData() {
    //   if (this.formBpm === true) {
    //     const params = { id: this.formData.dataId }
    //     getAction(this.url.queryById, params).then((res) => {
    //       if (res.success) {
    //         this.edit(res.result)
    //       }
    //     })
    //   }
    // },
    validateError(msg) {
      this.$message.error(msg)
    },
    popupCallback(row) {
      this.form.setFieldsValue(pick(row, 'createBy', 'createTime', 'contractCode', 'item', 'company', 'depositPark', 'parkNumber', 'ownerCode', 'ownerName', 'socialCreditcode', 'idNumber', 'contactMethod', 'projectCode', 'projectName', 'serviceArea', 'totalAmount', 'amountDetail', 'amountStandard', 'serviceStarttime', 'serviceEndtime', 'paymentMethod', 'earnestMoney', 'bpmStatus', 'isThreeSeven', 'contractFile'))
    },
    handleChangeTotal(event) {
      const convertCurrency = this.$convertCurrency(event)// 报销总金额大写转换
      this.form.setFieldsValue({ amountDetail: convertCurrency })
    },
    validateServicetime(rule, value, callback) {
      const form = this.form
      const data = form.getFieldsValue(['serviceStarttime', 'serviceEndtime'])
      const service_endtime = this.getDateTime(data.serviceEndtime)
      const service_starttime = this.getDateTime(data.serviceStarttime)
      if (service_endtime && service_starttime && service_starttime >= service_endtime) {
        callback('服务开始时间必须小于服务结束时间')
      }
      callback()
    },
    validateDate(type, value, row, column, callback, target) {
      if (type === 'blur' || type === 'change') {
        const { values } = target.getValuesSync({ validate: false, rowIds: [row.id] })
        if (values.length <= 0) {
          callback()
          return
        }
        const start_date = this.getDateTime(values[0].startDate)
        const end_date = this.getDateTime(values[0].endDate)
        if (end_date && start_date && start_date >= end_date) {
          callback(false, '开始时间必须小于结束时间')
        }
        callback(true) // true = 通过验证
      } else {
        callback() // 不填写或者填写 null 代表不进行任何操作
      }
    },
    validateCollectionDate(type, value, row, column, callback, target) {
      if (type === 'blur' || type === 'change') {
        const { values } = target.getValuesSync({ validate: false, rowIds: [row.id] })
        if (values.length <= 0) {
          callback()
          return
        }
        const collectionDate = this.getDateTime(values[0].collectionDate)
        const end_date = this.getDateTime(values[0].endDate)
        if (end_date && collectionDate && collectionDate >= end_date) {
          callback(false, '应收日期必须小于账单结束时间')
        }
        callback(true) // true = 通过验证
      } else {
        callback() // 不填写或者填写 null 代表不进行任何操作
      }
    },
    handleOk2() {
      const { values } = this.$refs[this.refKeys[1]].getValuesSync({ validate: false })
      if (values.length <= 0) {
        this.$message.warning('至少填写一行租赁合同款项信息')
        return false
      }
      this.handleOk()
    },
    houseCodeCallback(row, props) {
      if (row.houseCode) {
        const rows = []
        Object.keys(row).forEach(key => {
          const list = row[key] ? row[key].split(',') : []
          list.forEach((item, i) => {
            rows[i] ? '' : rows[i] = {}
            rows[i][key] = item
          })
        })
        const { values } = props.target.getValuesSync({ validate: false })
        const list = JSON.parse(JSON.stringify(values))
        list.forEach((item, i) => {
          if (item.id === props.rowId) {
            const currentRow = rows.shift()
            currentRow.id = props.rowId
            list[i] = currentRow
          }
        })
        if (rows.length > 0) {
          rows.forEach(item => {
            list.push(item)
          })
        }
        this.xyParkPropertycontractDetailTable.dataSource = list
        this.setServiceArea()
      } else { // 清空时，清空行数据
        props.target.setValues([{
          rowKey: props.rowId,
          values: { houseCode: '', buildingCode: '', buildingName: '', projectCode: '', projectName: '', floor: '', buildingArea: '', propertyArea: '', decoration: '', houseType: '' }
        }])
        this.setServiceArea()
      }
    },
    setServiceArea() { // 汇总主表服务面积
      setTimeout(() => {
        const { values } = this.$refs[this.refKeys[0]].getValuesSync({ validate: false })
        let serviceArea = 0
        values.forEach((item, i) => {
          serviceArea += Number(item.buildingArea)
        })
        this.form.setFieldsValue({ serviceArea: serviceArea })
      }, 100)
    },
    getDateTime(date) {
      let date_ = date
      if (date_) {
        date_ = this.dateFtt('yyyy-MM-dd', new Date(date_))
      }
      return date_ && new Date(date_).getTime()
    },
    dateFtt(fmt, date) { // author: meizz
      var o = {
        'M+': date.getMonth() + 1, // 月份
        'd+': date.getDate(), // 日
        'h+': date.getHours(), // 小时
        'm+': date.getMinutes(), // 分
        's+': date.getSeconds(), // 秒
        'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
        'S': date.getMilliseconds() // 毫秒
      }
      if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) }
      }
      return fmt
    }

  }
}
</script>

<style scoped>
</style>
